package 行为型模式.模板;

/**
 * @ClassNameTemplateTest
 * @Description
 * @Author
 * @Date2021/12/20 20:45
 **/
public class TemplateTest {
    public static void main(String[] args) {
        System.out.println("=========Java课程start=========");
        JavaCourse java = new JavaCourse();
        java.setNeedCheckHomework(true);
        java.createCourse();
        System.out.println("=========Python课程start=========");
        PythonCourse python = new PythonCourse();
        python.setNeedCheckHomework(false);
        python.createCourse();
    }
}

// 抽象课程
abstract class AbstractCourse {
    public final void createCourse() {
        //1、发布预习资料
        postPreResource();

        //2、制作课件
        createPPT();

        //3、在线直播
        liveVideo();

        //4、提交课堂笔记
        postNote();

        //5、提交源码
        postResource();

        //6、布置作业
        postHomework();

        //7、检查作业
        if (needCheckHomework()) {
            checkHomework();
        }
    }

    protected abstract void checkHomework();

    //钩子方法
    protected boolean needCheckHomework() {
        return false;
    }

    protected void postHomework() {
        System.out.println("布置作业");
    }

    protected void postNote() {
        System.out.println("提交课程笔记");
    }

    protected void postResource() {
        System.out.println("提交源码");
    }

    protected void liveVideo() {
        System.out.println("在线直播");
    }

    protected void createPPT() {
        System.out.println("制作课件");
    }

    protected void postPreResource() {
        System.out.println("发布预习资料");
    }
}

// Java课程
class JavaCourse extends AbstractCourse {
    private boolean needCheckHomework = false;
    public void setNeedCheckHomework(boolean needCheckHomework) {
        this.needCheckHomework = needCheckHomework;
    }
    @Override
    protected boolean needCheckHomework() {
        return this.needCheckHomework;
    }
    @Override
    protected void checkHomework() {
        System.out.println("检查Java作业");
    }
}

class PythonCourse extends AbstractCourse {
    private boolean needCheckHomework = false;
    public void setNeedCheckHomework(boolean needCheckHomework) {
        this.needCheckHomework = needCheckHomework;
    }
    @Override
    protected boolean needCheckHomework() {
        return this.needCheckHomework;
    }
    @Override
    protected void checkHomework() {
        System.out.println("检查Python作业");
    }
}
